﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CDSBDemandControlService
{
    public static class CommonFunctions
    {
        public static bool CheckExistsWithin(this string Item, List<string> Collection)
        {
            return Collection.Contains(Item);
        }

        public static string ToInlineString(this List<string> collection)
        {
            string inLineString = " ";

            foreach (string item in collection)
            {
                inLineString += inLineString[inLineString.Length - 1] == '\'' ? ",'" + item + "'" : "'" + item + "'";
            }

            return inLineString.Trim();
        }

        public static string ToInlineString(this List<DeveloperModel> developers)
        {
            string inLineString = " ";

            foreach (DeveloperModel developer in developers)
            {
                inLineString += inLineString[inLineString.Length - 1] == '\'' ? ",'" + developer.DeveloperName + "'" : "'" + developer.DeveloperName + "'";
            }

            return inLineString.Trim();
        }

        public static List<String> ToNameList(this List<DeveloperModel> developers)
        {
            List<String> NameList = new List<string>();

            foreach (DeveloperModel developer in developers)
            {
                NameList.Add(developer.DeveloperName);
            }

            return NameList;
        }

        public static string GetDeveloperTeam(this string developerName, List<DeveloperModel> developers) 
        {
            string Team = "";

            foreach (DeveloperModel developer in developers)
            {
                if (developer.DeveloperName == developerName) 
                {
                    Team = developer.DeveloperTeam;
                    break;
                }
            }

            if (Team.Length == 0)
                throw new Exception("Developer Team Not Found");
            else
                return Team;
        }
    }
}
